package com.itheima.test6;

import org.junit.Before;
import org.junit.Test;

import java.lang.reflect.Method;

/**
 * @Author:gy
 * @Date: 2025/09/06 11:38
 * @Description:
 */
public class Demo {
    Class clazz;
    @Before
    public void getClazz() throws Exception {
        clazz = Class.forName("com.itheima.test6.People");
    }
    //返回所有的方法 不包括私有 包括继承
    @Test
    public void method1(){
        Method[] method = clazz.getMethods();
        for (Method method1 : method) {
            System.out.println(method1);
        }
    }
    //返回本类的方法  包括私有
    @Test
    public void method2(){
        Method[] method = clazz.getDeclaredMethods();
        for (Method method1 : method) {
            System.out.println(method1);
        }

    }
    //返回本类的单个方法  不包括私有
    @Test
    public void method3() throws NoSuchMethodException {
        Method show2 = clazz.getMethod("show2", String.class);
        Method show3 = clazz.getMethod("show3");
        //Method show = clazz.getMethod("show");
        //System.out.println(show);
        System.out.println(show2);
        System.out.println(show3);
    }
    //获取单个的方法 包括公共和私有的都可以
    @Test
    public void method4() throws NoSuchMethodException {
        Method show2 = clazz.getDeclaredMethod("show2", String.class);
        Method show3 = clazz.getDeclaredMethod("show3");
        Method show = clazz.getDeclaredMethod("show");
        System.out.println(show);
        System.out.println(show2);
        System.out.println(show3);
    }
}
